package com.gym.utils;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * MD5 加密工具类
 * @author 江雪林
 * @create 2021-01-29
 */
public class MD5Util {

    /**
     *   对字符串 MD5 加盐值加密
     *
     * @param value 传入要加密的字符串
     * @param saltValue 传入要加的盐值
     * @return MD5加密后生成32位(小写字母+数字)字符串
     */
    public static String MD5 (String value, String saltValue) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(value.getBytes());
            md.update(saltValue.getBytes());
            return new BigInteger(1,md.digest()).toString(16);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            System.out.println("md5 "+value+"加密失败！");
            return null;
        }
    }
    public static void main(String[] args) {
      /*  String [] name= {"张三","李四",
                "Tom",
                "Ava",
                "Lily",
                "王五",
                "Emma",
                "Mike",
                "Jack",
                "Tylor",
                "马六",
                "Chloe"};*/
        String name="菜菜重坦冲锋";
        String pwd="123456";
        String pass="";
        /*for (int i=0;i<name.length;i++){
            pass=MD5(pwd,name[i]);
            System.out.println( name[i]+"加密后的值:\n"+pass);
        }*/

        pass= MD5Util.MD5(pwd,name);
        System.out.println( name+"加密后的值:\n"+pass);
    }

}

